class Message < ActiveRecord::Base
  validates_presence_of :message, :user_id, :mobile_mum
  
  belongs_to :user
  
  after_create :save_geoip
  
  def self.per_page
    20
  end
  
  def has_position?
    return false if self.position.blank?
    return true
  end
  
  
  def self.last_located
  	Message.find(:first, :conditions => "position not like ''", :order => "created_at DESC")
  end
  
  def save_geoip
  	unless self.ip.blank?
     loc = GeoIP.new(GEOIPDB).city(self.ip)
     self.position = "#{loc[9]},#{loc[10]}"
     self.save
 	end
  end
end
